﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;

public partial class index : System.Web.UI.Page
{
    int ToatalCountRecord;//总记录数 
    int PageItem = 10;
    //private System.ComponentModel.BackgroundWorker backgroundWorker1;//每页显示的条数 
    int CurrentPage = 1;//当前页数 
    int type = 0;//当前页数 

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["Type"] != null)
            {
                type = int.Parse(Request.QueryString["Type"].ToString());
                if (Request.QueryString["page"] != null)
                {
                    if (!Int32.TryParse(Request.QueryString["page"].ToString(), out CurrentPage))
                    {

                        //bind();
                        Response.Redirect("index.aspx");
                    }
                    if (Int32.Parse(Request.QueryString["page"].ToString()) == 1)
                    {

                    }
                }
                else
                {
                    CurrentPage = 1;

                }
                bind(type);
            }
            else
            {
                Response.Redirect("../");
            }
        }
    }
    private void bind(int typeid)
    {
        //新闻显示

        OleDbDataAdapter da = WebSet.GetProForPtypeid(typeid);
        DataSet ds = new DataSet();
        int startRecord = (CurrentPage - 1) * PageItem;
        da.Fill(ds, startRecord, PageItem, "a");
        this.ListView1.DataSource = ds.Tables["a"].DefaultView;
        this.ListView1.DataBind();
        ToatalCountRecord = WebSet.GetCountForSql("select Count(*) from [Product] Where Ptypeid=" + typeid + " ");
        PageInfo.InnerHtml = Pagecode.BuildPages(ToatalCountRecord, PageItem, CurrentPage, 5, 0, 0, "Product-List.aspx?Type=" + typeid + "&page=", "", "");

    }
}